package com.editso.haier.controller.admin;

import com.editso.haier.annon.Admin;
import com.editso.haier.result.Result;
import com.editso.haier.service.CustomerService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Admin
@RestController
@RequestMapping("/customer")
@RequiresRoles("admin")
public class CustomerController {

    private CustomerService customerService;

    @Autowired
    public void setCustomerService(CustomerService customerService) {
        this.customerService = customerService;
    }

    @PostMapping("/assets")
    public Result newAssets(@RequestBody Map<String, String> map){
        return customerService.createAssets(
                map.get("name"),
                map.get("desc"));
    }

    @PostMapping("/assets/{id}")
    public Result appendAssets(@PathVariable Integer id, @RequestBody Map<String, Object> map){
        return customerService.appendAssets(id, map);
    }


    @DeleteMapping("/assets/{id}")
    public Result deleteAssets(@PathVariable Integer id, String aid){
        return customerService.deleteAssets(id, aid);
    }

    @GetMapping("/assets")
    public Result getAssets(Integer id){
        return customerService.getAssets(id);
    }
}
